home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Preference⁄Setup Func. Example / SetupFunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-30  |  7.7 KB  |  222 lines  |  [TEXT/MPS ]

  1. /*
  2.     This Setup Function calls the System 7 PBCatSearch routine to search for the first
  3.     SimpleText application found on the default volume.  If a copy of the application is
  4.     found, the folder's FSSpec is returned to the Installer to be considered for the 
  5.     suggested installation folder.
  6.     
  7.     This function does nothing under pre-7.0 systems.
  8.     
  9.     You can use the accompanying routines to display information in the Installer Debugger 
  10.     to help you learn and debug your Setup Function.
  11.     
  12. */
  13.  
  14. #ifndef __Files__
  15. #include <Files.h>
  16. #endif
  17.  
  18. #ifndef __GestaltEqu__
  19. #include <GestaltEqu.h>
  20. #endif
  21.  
  22. #ifndef __Memory__
  23. #include <Memory.h>
  24. #endif
  25.  
  26. #ifndef __OSUtils__
  27. #include <OSUtils.h>
  28. #endif
  29.  
  30. #ifndef __Packages__
  31. #include <Packages.h>
  32. #endif
  33.  
  34. #ifndef __InstallerScript__
  35. #include "InstallerScript.h"
  36. #endif
  37.  
  38. #ifndef __ActionHandlerHeader__
  39. #include "ActionHandlerHeader.h"
  40. #endif
  41.  
  42. #include <TextUtils.h>
  43.  
  44.  
  45. void DisplayPreferenceInfo( EnvironmentSetupPBPtr        pSetupPBPtr, long pResultCode );
  46.  
  47. long SetupFunction( EnvironmentSetupPBPtr        pSetupPBPtr )
  48. {
  49.  
  50.     #define            kOptBufferSize    0x4000
  51.  
  52.     long            theResult = 0;
  53.     long            theSysVersionNum;
  54.     OSErr            theErr;
  55.     CInfoPBRec        theFirstSearchCriteria;
  56.     CInfoPBRec        theSecondSearchCriteria;
  57.     CSParam            theCatParamBlock;
  58.     FSSpec            theMatchedFSSpec;
  59.     long            theMaxNumOfMatches = 1;
  60.     char            *theOptionalBuffer=NewPtr(kOptBufferSize);
  61.     CInfoPBRec        theCatInfoParamBlock;
  62.     Str255            theTempStr255;
  63.     short            theByteCtr;
  64.  
  65.  
  66.     // If you want to select the default target volume and/or system disk set these fields
  67.  
  68.     Gestalt( 'sysv', &theSysVersionNum );
  69.     if( theSysVersionNum >= 0x00000700 ) {
  70.     
  71.         theCatParamBlock.ioCompletion        = NULL;
  72.         theCatParamBlock.ioNamePtr            = NULL;
  73.         theCatParamBlock.ioVRefNum            = pSetupPBPtr->fTargetFSSpec.vRefNum;
  74.         
  75.            theCatParamBlock.ioMatchPtr            = (FSSpecArrayPtr)&theMatchedFSSpec;        /* match array */
  76.         theCatParamBlock.ioReqMatchCount    = theMaxNumOfMatches;                        /* maximum allowable matches */
  77.         theCatParamBlock.ioSearchBits        = fsSBFlFndrInfo + fsSBFlAttrib;            /* search criteria selector */
  78.         theCatParamBlock.ioSearchInfo1        = &theFirstSearchCriteria;                    /* search values and range lower bounds */
  79.         theCatParamBlock.ioSearchInfo2        = &theSecondSearchCriteria;                    /* search values and range upper bounds */
  80.         theCatParamBlock.ioSearchTime        = 0;                                        /* length of time to run search */
  81.         theCatParamBlock.ioCatPosition.initialize    = 0;                                /* current position in the catalog */
  82.         theCatParamBlock.ioOptBuffer        = theOptionalBuffer;                        /* optional performance enhancement buffer */
  83.         theCatParamBlock.ioOptBufSize        = kOptBufferSize;                            /* size of buffer pointed to by ioOptBuffer */
  84.     
  85.         theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdType        = 'APPL';
  86.         theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator        = 'ttxt';
  87.         theFirstSearchCriteria.hFileInfo.ioFlAttrib                    = 0x00;
  88.  
  89.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdType        = 0xFFFFFFFF;        /*the type of the file*/
  90.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator    = 0xFFFFFFFF;        /*file's creator*/
  91.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFlags        = 0x0000;            /*flags ex. hasbundle,invisible,locked, etc.*/
  92.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.h    = 0x0000;            /*file's location in folder*/
  93.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.v    = 0x0000;            /*file's location in folder*/
  94.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFldr        = 0x0000;            /*folder containing file*/
  95.         theSecondSearchCriteria.hFileInfo.ioFlAttrib                = 0x10;
  96.         
  97.         theErr = PBCatSearchSync( &theCatParamBlock );
  98.     
  99.         if( theErr == noErr && theCatParamBlock.ioActMatchCount >= 1 ) {
  100.             
  101.             theCatInfoParamBlock.dirInfo.ioNamePtr         = (StringPtr)&theTempStr255;
  102.             theCatInfoParamBlock.dirInfo.ioVRefNum         = theMatchedFSSpec.vRefNum;
  103.             theCatInfoParamBlock.dirInfo.ioFDirIndex     = -1;
  104.             theCatInfoParamBlock.dirInfo.ioDrDirID         = theMatchedFSSpec.parID;
  105.             theErr = PBGetCatInfoSync( &theCatInfoParamBlock );
  106.  
  107.             if( theErr == noErr ) {
  108.                 pSetupPBPtr->fTargetFSSpec.vRefNum    = theCatInfoParamBlock.dirInfo.ioVRefNum;
  109.                 pSetupPBPtr->fTargetFSSpec.parID    = theCatInfoParamBlock.dirInfo.ioDrParID;
  110.                 
  111.                 for( theByteCtr = 0; theByteCtr <= theCatInfoParamBlock.dirInfo.ioNamePtr[0]; theByteCtr++ )
  112.                     pSetupPBPtr->fTargetFSSpec.name[theByteCtr]    = theCatInfoParamBlock.dirInfo.ioNamePtr[theByteCtr];
  113.             }
  114.         DisposePtr(theOptionalBuffer);
  115.         }
  116.     
  117.     }
  118.     else {
  119.     
  120.         // Implement the pre-7.0 search code here
  121.     
  122.     }
  123.  
  124.     DisplayPreferenceInfo( pSetupPBPtr, theResult );
  125.     return theResult;
  126. }
  127.  
  128.  
  129. // -------------------------------------------------------------------------------------------------------------------------------------
  130. // The routines below are for displaying the contents of the parameter block passed to the Setup Function.
  131. // Call DisplayPreferenceInfo to write this information to the Installer Debugger.
  132.  
  133. void MakeFilePath( FSSpec* pFileFSSpec, Str255  pFilePath )
  134. {
  135.     
  136.     CInfoPBRec        cPBRec;
  137.     Str255            directoryName = "";
  138.     short            i;
  139.     OSErr            theErr;
  140.  
  141.     // Get the file name
  142.     for( i=0;i<=pFileFSSpec->name[0];i++)
  143.         pFilePath[i] = pFileFSSpec->name[i];
  144.  
  145.     cPBRec.hFileInfo.ioCompletion = NULL;
  146.     cPBRec.hFileInfo.ioNamePtr = directoryName;
  147.     cPBRec.hFileInfo.ioFDirIndex = -1;
  148.     cPBRec.hFileInfo.ioDirID = pFileFSSpec->parID;
  149.     cPBRec.hFileInfo.ioVRefNum = pFileFSSpec->vRefNum;
  150.     theErr = PBGetCatInfo( &cPBRec, 0 );
  151.  
  152.     // Preappend directoryName
  153.     BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
  154.     for( i=1;i<=directoryName[0];i++)
  155.         pFilePath[i] = directoryName[i];
  156.     pFilePath[i] = ':';
  157.     pFilePath[0] += directoryName[0] + 1;
  158.  
  159.     while ( theErr == noErr && cPBRec.dirInfo.ioDrParID != 1 && pFilePath[0] + directoryName[0] + 1 < 255 ) {
  160.  
  161.     // Preappend directoryName
  162.         cPBRec.hFileInfo.ioDirID = cPBRec.dirInfo.ioDrParID;
  163.         cPBRec.hFileInfo.ioFDirIndex = -1;
  164.         theErr = PBGetCatInfo( &cPBRec, 0 );
  165.  
  166.         if( theErr == noErr ) {
  167.             // Preappend directoryName
  168.             BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
  169.             for( i=1;i<=directoryName[0];i++)
  170.                 pFilePath[i] = directoryName[i];
  171.             pFilePath[i] = ':';
  172.             pFilePath[0] += directoryName[0] + 1;
  173.         }
  174.     }
  175.  
  176. }
  177.  
  178. void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
  179. {
  180.     long    theResult;
  181.     RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );    
  182. }
  183.  
  184. void DisplayPreferenceInfo( EnvironmentSetupPBPtr    pSetupPBPtr, long pResultCode )
  185. {
  186.  
  187. StringPtr                    kBeginCallPart1                    = "\p=>========================== Begin Setup Function Call ====";
  188. StringPtr                    kBeginCallPart3                    = "\p==================================================";
  189.  
  190. StringPtr                    kEndCallPart1                    = "\p-<-------------------------- End Setup Function Call ------ ";
  191. StringPtr                    kEndCallPart3                    = "\p ----------------------------\n";
  192.  
  193. StringPtr                    kResultText                        = "\pResult Code: ";
  194.  
  195. StringPtr                    kTargetFolderPathText            = "\p    Target Folder Path:  ";
  196. StringPtr                    kSystemDiskText                    = "\p      System Disk Name:  ";
  197.  
  198. Str255                        tempNumStr;    
  199. Str255                        tempStr255;    
  200. FSSpec                        tempFSSpec;
  201.  
  202.     // -- Beginning line
  203.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kBeginCallPart1, kBeginCallPart3, "\p", "\p" );
  204.  
  205.     // -- Target Folder Path
  206.     MakeFilePath( &(pSetupPBPtr->fTargetFSSpec), tempStr255 );
  207.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kTargetFolderPathText, tempStr255, "\p", "\p" );
  208.  
  209.     // —— System Disks Name
  210.     tempFSSpec.name[0] = 0;
  211.     tempFSSpec.parID = 2;
  212.     tempFSSpec.vRefNum = pSetupPBPtr->fSystemVRefNum;
  213.     MakeFilePath( &tempFSSpec, tempStr255 );
  214.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kSystemDiskText, tempStr255, "\p", "\p" );
  215.  
  216.     // -- Ending line
  217.     NumToString( pResultCode, tempNumStr );
  218.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kEndCallPart1, kResultText, tempNumStr, kEndCallPart3 );
  219. }
  220.  
  221. #include "InstallerCallbackGlue.c"
  222.